package com.yanqu.road.server.manger.activity.operamask;

import com.yanqu.road.entity.activity.operamask.OperaMaskConfig;
import com.yanqu.road.entity.activity.operamask.config.OperaMaskSceneConfig;
import com.yanqu.road.entity.activity.operamask.config.OperaMaskSkillConfig;
import com.yanqu.road.entity.activity.operamask.game.OperaMaskSkill;
import com.yanqu.road.entity.enums.eOperaMaskSkillType;

import java.util.ArrayList;
import java.util.List;

public class OperaMaskSkillLogic {

    private static List<Integer> getSkillEffectValue(List<OperaMaskSkill> skillList, OperaMaskConfig config, eOperaMaskSkillType skillType) {
        for (OperaMaskSkill skill : skillList) {
            if (skill.getSkillId() == skillType.getValue()) {
                List<OperaMaskSkillConfig> skillConfigList = config.getSkillConfigMap().get(skill.getSkillId());
                OperaMaskSkillConfig skillConfig = skillConfigList.get(skill.getSkillLevel() - 1);
                return skillConfig.getSkillParamList();
            }
        }
        return null;
    }

    // ======================== 拿技能效果 =========================

    public static int getSkill01Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill01);
        return list != null ? list.get(0) / 1000 : 0;
    }

    public static List<Integer> getSkill02Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill02);
        List<Integer> tmp = new ArrayList<>();
        if (list == null) {
            tmp.add(0); // 数量
            tmp.add(0); // 概率，千分比
        } else {
            tmp.add(list.get(0) / 1000);
            tmp.add(list.get(1));
        }
        return tmp;
    }

    public static boolean getSkill03Effect(List<OperaMaskSkill> skillList) {
        return skillList.stream().anyMatch(item -> item.getSkillId() == eOperaMaskSkillType.Skill03.getValue());
    }

    public static int getSkill04Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill04);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill05Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill05);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill06Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill06);
        return list != null ? list.get(0) : 0;
    }

    public static boolean getSkill07Effect(List<OperaMaskSkill> skillList) {
        return skillList.stream().anyMatch(item -> item.getSkillId() == eOperaMaskSkillType.Skill07.getValue());
    }

    public static boolean getSkill08Effect(List<OperaMaskSkill> skillList) {
        return skillList.stream().anyMatch(item -> item.getSkillId() == eOperaMaskSkillType.Skill08.getValue());
    }

    public static int getSkill09Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill09);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill10Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill10);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill11Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill11);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill12Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill12);
        return list != null ? list.get(0) / 1000 : 0;
    }

    public static int getSkill13Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill13);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill14Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill14);
        return list != null ? list.get(0) / 1000 : 0;
    }

    public static List<Integer> getSkill15Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill15);
        List<Integer> tmp = new ArrayList<>();
        if (list == null) {
            tmp.add(0);
            tmp.add(0);
            tmp.add(0);
        } else {
            tmp.add(list.get(0) / 1000);
            tmp.add(list.get(1) / 1000);
            tmp.add(list.get(2));
        }
        return tmp;
    }

    public static int getSkill16Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill16);
        return list != null ? list.get(0) : 0;
    }

    public static boolean getSkill17Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config, int skillEffectAmount) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill17);
        // 每回合最多触发n次
        return list != null ? list.get(0) / 1000 > skillEffectAmount : false;
    }

    public static List<Integer> getSkill18Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill18);
        return list;
    }

    public static List<Integer> getSkill19Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill19);
        if (list == null) {
            return null;
        } else {
            List<Integer> tmp = new ArrayList<>();
            tmp.add(list.get(0) / 1000);
            tmp.add(list.get(1) / 1000);
            return tmp;
        }
    }

    public static List<Integer>  getSkill20Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill20);
        if (list == null) {
            return null;
        } else {
            List<Integer> tmp = new ArrayList<>();
            tmp.add(list.get(0));
            tmp.add(list.get(1) / 1000);
            return tmp;
        }
    }

    public static int getSkill21Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill21);
        return list != null ? list.get(0) / 1000 : 0;
    }

    public static int getSkill22Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill22);
        return list != null ? list.get(0) : 0;
    }

    public static int getSkill99Effect(List<OperaMaskSkill> skillList, OperaMaskConfig config) {
        List<Integer> list = getSkillEffectValue(skillList, config, eOperaMaskSkillType.Skill99);
        return list != null ? list.get(0) : 0;
    }

    // ================== 剧目技能 ===================

    public static List<Integer> getSceneSkillEffectList(OperaMaskSceneConfig sceneConfig, eOperaMaskSkillType skillType) {
        if (null == sceneConfig) {
            return null;
        }
        if (skillType == eOperaMaskSkillType.Skill1003 && sceneConfig.getSceneId() == 2
                || skillType == eOperaMaskSkillType.Skill1002 && sceneConfig.getSceneId() == 3
                || skillType == eOperaMaskSkillType.Skill1005 && sceneConfig.getSceneId() == 4
                || skillType == eOperaMaskSkillType.Skill1004 && sceneConfig.getSceneId() == 1
                || skillType == eOperaMaskSkillType.Skill1006 && sceneConfig.getSceneId() == 5) {
            return sceneConfig.getEffectParamList();
        }
        return null;
    }

}
